<?php
/*
 * 根据数据返回Option
 */
function getArrayToOptions($arr,$selected=0, $keyname = 'id', $valuename = 'mc',$levelname='level') {
    $returnHtml = '';
    foreach ($arr as $row) {
        $returnHtml.= '<option value="' . $row[$keyname] . '" ';
        $returnHtml.=($selected == $row[$keyname]) ? "selected='ture'" : '';
        $returnHtml.='>';
        if (isset($row[$levelname])){
            //如果存在分级
            if ($row[$levelname] >0){
                $returnHtml.=str_repeat('&nbsp;', $row[$levelname] * 4);
            }
        }
        $returnHtml.=htmlspecialchars(addslashes($row[$valuename])) . '</option>';
    }
    return $returnHtml;
}
